#!/usr/bin/env python
#coding=utf-8
# 元组
print tuple('bar') # ('b', 'a', 'r')
# 不能创建只有一个元素的元组

# 浅拷贝
person = ['name', ['savings', 100.00]]
hubby = person[:]
wifey = list(person)
print [id(x) for x in person, hubby, wifey]
hubby[0] = 'joe'
wifey[0] = 'jane'
print hubby, wifey
hubby[1][1] = 50.00 # 当丈夫的存款变了 妻子的存款也变了  列表的第二个元素是浅拷贝 对象是新的但是内容不是 进行浅拷贝时 字符串（不可变类型） 重新生成了对象
print hubby, wifey
print '-'*20
person = ['name', ['savings', 100.00]]
import copy
hubby = person
wifey = copy.deepcopy(person)
print [id(x) for x in person, hubby, wifey]
hubby[0] = 'joe'
wifey[0] = 'jane'
print hubby, wifey
hubby[1][1] = 50.0
print hubby, wifey
'''
[140616325065112, 140616325078336, 140616325109160]
['joe', ['savings', 100.0]] ['jane', ['savings', 100.0]]
['joe', ['savings', 50.0]] ['jane', ['savings', 50.0]]
--------------------
[140616325108152, 140616325108152, 140616325078336]
['joe', ['savings', 100.0]] ['jane', ['savings', 100.0]]
['joe', ['savings', 50.0]] ['jane', ['savings', 100.0]]
'''

# 创建字典
ddict = dict((['x', 1], ['y', 2]))
print ddict

print {}.fromkeys(('foo', 'bar')) # 默认 key的值 为 None
print {}.fromkeys(('foo', 'bar'), -1)

# 遍历
dict2 = {'name':'earth', 'port':80}
for key in dict2:
	print ("%s %s" % (key, dict2[key]))

# 清空 字典
# del , .clear(), .pop('key')


print 'name' in dict2
print dict(zip(('x', 'y'), (1,2)))


dict2 = {'host':'earth', 'port':80}
dict3 = {'host':'venus', 'server':'http'}
dict2.update(dict3) # 用dict3更新dict2，当dict2中没有的数据出现
print dict2 # {'host': 'venus', 'port': 80, 'server': 'http'}
print dict2['host']
# print dict2['xxx'] # error
print dict2.get('xxx') # None
print dict2.keys()
print dict2.items()
print dict2.setdefault('port', 8080) # 当键不在时设置的键值 所以8080不成功，还是80
print dict2.items()

